XR API 2.4
Loading...
Searching...
No Matches
xr_math.h
Go to the documentation of this file.
1
23#ifndef XR_MATH_H_
24#define XR_MATH_H_
25
26#include <math.h>
27
34 float x;
35
37 float y;
38
40 float z;
41
43 float w;
44
48 SonyOzQuaternionf() : x(0.f), y(0.f), z(0.f), w(1.f) {}
49
57 SonyOzQuaternionf(float in_x, float in_y, float in_z, float in_w)
58 : x(in_x), y(in_y), z(in_z), w(in_w) {}
59
60 void operator=(float a[4]) {
61 this->x = a[0];
62 this->y = a[1];
63 this->z = a[2];
64 this->w = a[3];
65 }
66};
67
74 float x;
75
77 float y;
78
80 float z;
81
85 SonyOzVector3f() : x(0.f), y(0.f), z(0.f) {}
86
93 SonyOzVector3f(float in_x, float in_y, float in_z)
94 : x(in_x), y(in_y), z(in_z) {}
95
97 return SonyOzVector3f(x + a.x, y + a.y, z + a.z);
98 }
100 return SonyOzVector3f(x - a.x, y - a.y, z - a.z);
101 }
102
104 return SonyOzVector3f(x * a, y * a, z * a);
105 }
107 return SonyOzVector3f(x / a, y / a, z / a);
108 }
109
110 void operator=(float a[3]) {
111 this->x = a[0];
112 this->y = a[1];
113 this->z = a[2];
114 }
115
116 float Dot(SonyOzVector3f a) { return x * a.x + y * a.y + z * a.z; }
117
118 void Normalize() {
119 float length = sqrtf(x * x + y * y + z * z);
120 x /= length;
121 y /= length;
122 z /= length;
123 }
124};
125
132 float x;
133
135 float y;
136
138 float z;
139
141 float w;
142
146 SonyOzVector4f() : x(0.f), y(0.f), z(0.f), w(0.f) {}
147
155 SonyOzVector4f(float in_x, float in_y, float in_z, float in_w)
156 : x(in_x), y(in_y), z(in_z), w(in_w) {}
157
159 return x * a.x + y * a.y + z * a.z + w * a.w;
160 }
161};
162
170 float matrix[4][4];
171
176 matrix[0][0] = 0.f;
177 matrix[0][1] = 0.f;
178 matrix[0][2] = 0.f;
179 matrix[0][3] = 0.f;
180 matrix[1][0] = 0.f;
181 matrix[1][1] = 0.f;
182 matrix[1][2] = 0.f;
183 matrix[1][3] = 0.f;
184 matrix[2][0] = 0.f;
185 matrix[2][1] = 0.f;
186 matrix[2][2] = 0.f;
187 matrix[2][3] = 0.f;
188 matrix[3][0] = 0.f;
189 matrix[3][1] = 0.f;
190 matrix[3][2] = 0.f;
191 matrix[3][3] = 0.f;
192 }
193
194 SonyOzMatrix4x4f(float x0, float x1, float x2, float x3, float y0, float y1,
195 float y2, float y3, float z0, float z1, float z2, float z3,
196 float w0, float w1, float w2, float w3) {
197 matrix[0][0] = x0;
198 matrix[0][1] = x1;
199 matrix[0][2] = x2;
200 matrix[0][3] = x3;
201 matrix[1][0] = y0;
202 matrix[1][1] = y1;
203 matrix[1][2] = y2;
204 matrix[1][3] = y3;
205 matrix[2][0] = z0;
206 matrix[2][1] = z1;
207 matrix[2][2] = z2;
208 matrix[2][3] = z3;
209 matrix[3][0] = w0;
210 matrix[3][1] = w1;
211 matrix[3][2] = w2;
212 matrix[3][3] = w3;
213 }
214
223 SonyOzVector4f in_z, SonyOzVector4f in_w) {
224 matrix[0][0] = in_x.x;
225 matrix[0][1] = in_x.y;
226 matrix[0][2] = in_x.z;
227 matrix[0][3] = in_x.w;
228 matrix[1][0] = in_y.x;
229 matrix[1][1] = in_y.y;
230 matrix[1][2] = in_y.z;
231 matrix[1][3] = in_y.w;
232 matrix[2][0] = in_z.x;
233 matrix[2][1] = in_z.y;
234 matrix[2][2] = in_z.z;
235 matrix[2][3] = in_z.w;
236 matrix[3][0] = in_w.x;
237 matrix[3][1] = in_w.y;
238 matrix[3][2] = in_w.z;
239 matrix[3][3] = in_w.w;
240 }
241
243 SonyOzVector4f m_0 =
244 SonyOzVector4f(matrix[0][0], matrix[0][1], matrix[0][2], matrix[0][3]);
245 SonyOzVector4f m_1 =
246 SonyOzVector4f(matrix[1][0], matrix[1][1], matrix[1][2], matrix[1][3]);
247 SonyOzVector4f m_2 =
248 SonyOzVector4f(matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3]);
249 SonyOzVector4f m_3 =
250 SonyOzVector4f(matrix[3][0], matrix[3][1], matrix[3][2], matrix[3][3]);
251
252 SonyOzVector4f a_0 = SonyOzVector4f(a.matrix[0][0], a.matrix[1][0],
253 a.matrix[2][0], a.matrix[3][0]);
254 SonyOzVector4f a_1 = SonyOzVector4f(a.matrix[0][1], a.matrix[1][1],
255 a.matrix[2][1], a.matrix[3][1]);
256 SonyOzVector4f a_2 = SonyOzVector4f(a.matrix[0][2], a.matrix[1][2],
257 a.matrix[2][2], a.matrix[3][2]);
258 SonyOzVector4f a_3 = SonyOzVector4f(a.matrix[0][3], a.matrix[1][3],
259 a.matrix[2][3], a.matrix[3][3]);
260
261 float m_00 = m_0 * a_0, m_01 = m_0 * a_1, m_02 = m_0 * a_2,
262 m_03 = m_0 * a_3;
263 float m_10 = m_1 * a_0, m_11 = m_1 * a_1, m_12 = m_1 * a_2,
264 m_13 = m_1 * a_3;
265 float m_20 = m_2 * a_0, m_21 = m_2 * a_1, m_22 = m_2 * a_2,
266 m_23 = m_2 * a_3;
267 float m_30 = m_3 * a_0, m_31 = m_3 * a_1, m_32 = m_3 * a_2,
268 m_33 = m_3 * a_3;
269
270 return SonyOzMatrix4x4f(SonyOzVector4f(m_00, m_01, m_02, m_03),
271 SonyOzVector4f(m_10, m_11, m_12, m_13),
272 SonyOzVector4f(m_20, m_21, m_22, m_23),
273 SonyOzVector4f(m_30, m_31, m_32, m_33));
274 }
275};
276
277#endif // XR_MATH_H_
4x4 matrix of type float
Definition xr_math.h:167
float matrix[4][4]
Definition xr_math.h:170
SonyOzMatrix4x4f operator*(SonyOzMatrix4x4f a)
Definition xr_math.h:242
SonyOzMatrix4x4f()
Constructor.
Definition xr_math.h:175
SonyOzMatrix4x4f(float x0, float x1, float x2, float x3, float y0, float y1, float y2, float y3, float z0, float z1, float z2, float z3, float w0, float w1, float w2, float w3)
Definition xr_math.h:194
SonyOzMatrix4x4f(SonyOzVector4f in_x, SonyOzVector4f in_y, SonyOzVector4f in_z, SonyOzVector4f in_w)
Constructor.
Definition xr_math.h:222
quaternion of type float
Definition xr_math.h:32
float y
y
Definition xr_math.h:37
SonyOzQuaternionf(float in_x, float in_y, float in_z, float in_w)
Constructor.
Definition xr_math.h:57
void operator=(float a[4])
Definition xr_math.h:60
float z
z
Definition xr_math.h:40
float x
x
Definition xr_math.h:34
SonyOzQuaternionf()
Constructor.
Definition xr_math.h:48
float w
w
Definition xr_math.h:43
3D vector of type float
Definition xr_math.h:72
float z
z
Definition xr_math.h:80
float x
x
Definition xr_math.h:74
SonyOzVector3f operator*(float a)
Definition xr_math.h:103
void Normalize()
Definition xr_math.h:118
float Dot(SonyOzVector3f a)
Definition xr_math.h:116
float y
y
Definition xr_math.h:77
void operator=(float a[3])
Definition xr_math.h:110
SonyOzVector3f operator-(SonyOzVector3f a)
Definition xr_math.h:99
SonyOzVector3f()
Constructor.
Definition xr_math.h:85
SonyOzVector3f operator/(float a)
Definition xr_math.h:106
SonyOzVector3f operator+(SonyOzVector3f a)
Definition xr_math.h:96
SonyOzVector3f(float in_x, float in_y, float in_z)
Constructor.
Definition xr_math.h:93
4D vector of type float
Definition xr_math.h:130
float w
w
Definition xr_math.h:141
SonyOzVector4f(float in_x, float in_y, float in_z, float in_w)
Constructor.
Definition xr_math.h:155
float operator*(SonyOzVector4f a)
Definition xr_math.h:158
float z
z
Definition xr_math.h:138
SonyOzVector4f()
Constructor.
Definition xr_math.h:146
float y
y
Definition xr_math.h:135
float x
x
Definition xr_math.h:132